package com.woman.beautylive.presentation.ui.main.setting;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.magiepooh.recycleritemdecoration.ItemDecorations;
import com.woman.beautylive.R;
import com.woman.beautylive.data.bean.room.HitList;
import com.woman.beautylive.data.repository.SourceFactory;
import com.woman.beautylive.domain.LocalDataManager;
import com.woman.beautylive.presentation.ui.base.BaseActivity;
import com.woman.beautylive.presentation.ui.base.recycler.SimpleRecyclerAdapter;
import com.woman.beautylive.presentation.ui.base.recycler.SimpleRecyclerHolder;
import com.woman.beautylive.util.L;
import com.woman.beautylive.util.PicUtil;

import java.util.List;

public class BlacklistActivity extends BaseActivity implements BlacklistInterface{

    private RecyclerView recyclerHitList;
    private BlacklistAdapter adapter;
    private BlacklistPresenter presenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_blacklist;
    }

    @Override
    protected void findViews(Bundle savedInstanceState) {
        presenter=new BlacklistPresenter(this);
        recyclerHitList = $(R.id.hitlist_recycler);
        recyclerHitList.setLayoutManager(new LinearLayoutManager(this));
        recyclerHitList.addItemDecoration(ItemDecorations.vertical(this)
                .type(0, R.drawable.divider_decoration_transparent_h1)
                .create());

    }

    @Override
    protected void init() {
        presenter.updateInform(LocalDataManager.getInstance().getLoginInfo().getToken());
        L.e("lw","我的token"+LocalDataManager.getInstance().getLoginInfo().getToken());
    }

    @Override
    public void showResult(List<HitList> list) {
        if (adapter == null) {
            adapter = new BlacklistAdapter(list);
            recyclerHitList.setAdapter(adapter);
        } else {
            adapter.setDataList(list);
        }
    }

    private class BlacklistAdapter extends SimpleRecyclerAdapter<HitList,
            BlacklistHolder> {
        public BlacklistAdapter(List<HitList> hitLists) {
            super(hitLists);
        }

        @Override
        protected int getItemLayoutId(int viewType) {
            return R.layout.item_hitlist_result;
        }

        @NonNull
        @Override
        protected BlacklistHolder createHolder(View view) {
            return new BlacklistHolder(view);
        }
    }

    private class BlacklistHolder extends SimpleRecyclerHolder<HitList> {

        private TextView tvNickname,tvUsername,tvId,tvCurroomnum;
        private ImageView imgGender, imgLevel;
        private ImageButton imgbtnChange;

        public BlacklistHolder(View itemView) {
            super(itemView);
            tvNickname = (TextView) itemView.findViewById(R.id.item_hitlist_nickname);
            tvUsername = (TextView) itemView.findViewById(R.id.item_hitlist_username);
            tvId = (TextView) itemView.findViewById(R.id.item_hitlist_id);
            tvCurroomnum = (TextView) itemView.findViewById(R.id.item_hitlist_curroomnum);
            imgGender = (ImageView) itemView.findViewById(R.id.item_hitlist_gender);
            imgLevel = (ImageView) itemView.findViewById(R.id.item_hitlist_img_level);
            imgbtnChange = (ImageButton) itemView.findViewById(R.id.item_hitlist_change);
        }

        @Override
        public void displayData(HitList data) {
            L.e("lw","我的HitList"+data.getId()+data.getNickname());
            tvId.setText(data.getId());
            tvCurroomnum.setText(data.getCurroomnum());
            tvNickname.setText(data.getNickname());
            tvUsername.setText(data.getUsername());
            imgGender.setImageResource(SourceFactory.isMale(data.getSex()) ?
                    R.drawable.ic_global_male : R.drawable.ic_global_female);
//            imgLevel.setImageResource(PicUtil.getLevelImageId(itemView.getContext(), Integer.parseInt(data.getEmceelecel())));
        }
    }
}
